/* eslint-disable no-unused-vars */
/* eslint-disable class-methods-use-this */
/* eslint-disable import/no-cycle */
/* eslint-disable react/no-danger */
/* eslint-disable no-param-reassign */
import React from 'react';
import BaseControl from './BaseControl';
import ControlPlus from './ControlPlus';
import ControlUtil from './ControlUtil';

/**
 * 基础容器控件
 */
class BaseContainerControl extends BaseControl {
  static create(props, dataProps, extProps) {
    return new BaseContainerControl(props, dataProps, extProps);
  }

  constructor(props, dataProps, extProps) {
    const dataProps2 = {
      title: '基础容器控件',
      type: 'BaseContainer',
      childControls: [], // 控件集合
      canAddChild: true,
      // height: 100, // 高度px，0为auto
      ...dataProps,
    };
    super(props, dataProps2, extProps);
    this.name = '基础容器控件';
    // this.icon = '';
  }

  // 控件基本初始化
  init(parentForm) {
    this.data.childControls.forEach((c) => {
      c.init(parentForm);
    });
  }

  // 加载json
  load(json) {
    this.data = { ...this.data, ...json };
    // 添加新元素
    // const orderControls = ControlUtil.loadForm(this.props.children, this.data.childControls);
    // this.data.childControls = orderControls;
  }

  // 获取后端协议json，后台解析使用
  getPropertyJson() {
    const childJsons = this.data.childControls.map((c, index) => {
      return c.getPropertyJson();
    });
    return { ...this.data, childControls: childJsons };
  }

  // 获取前端设计模型json标准
  getDesignModelJson() {
    const childJsons = this.data.childControls.map((c, index) => {
      return c.getPropertyJson();
    });
    return { ...this.data, childControls: childJsons };
  }

  // 获取formItem控件的value值
  getJsonValue(jsonValues) {
    this.data.childControls.forEach((c) => {
      c.getJsonValue(jsonValues);
    });
  }

  // 设置formItem控件的value值
  setJsonValue(jsonValues) {
    const value2 = jsonValues || [];
    this.data.childControls.forEach((item, index) => {
      item.setJsonValue(value2);
    });
  }

  getPropertyTabs(parentForm) {
    return [...super.getPropertyTabs(parentForm)];
  }

  getDesignControl(parentForm) {
    return <React.Fragment {...this.extProps} />;
  }
}

export default BaseContainerControl;
